using UnityEngine;

public class EnemyCheckPos : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.gameObject.GetComponent<Player>()!=null)
        {
            //玩家停下
            collision.gameObject.GetComponent<Player>().StopPlayer();
            //如果我的父物体是enemy
            if(transform.parent.GetComponent<Enemy>()!=null)
            {
                Enemy this_enemy = transform.parent.GetComponent<Enemy>();
                //查看是否需要鼠符咒解锁
                if(this_enemy.data.isSculp&&this_enemy.data.isActive)
                {
                    //是否佩戴鼠符咒
                    if(TurnManager.instance.SeekTurn("鼠"))
                    {
                        //播放雕像消失特效
                        this_enemy.transform.Find("Sprite/Sculpture").GetComponent<Animator>().SetTrigger("Run");
                        //显示出物品
                        this_enemy.transform.Find("Sprite").GetComponent<SpriteRenderer>().enabled=true;
                        TipSayManager.Instance.Say("雕像发生了变化！！！");
                        this_enemy.data.isActive=false;
                        AchiManager.instance.UnLockAchi("公主？");
                    }
                    else
                    {
                        TipSayManager.Instance.Say("需要佩戴<color=yellow> 鼠符咒 </color>");
                    }

                    return;
                }

                if (transform.parent.GetComponent<Enemy>().needSay)
                {
                    //打开
                    this_enemy.sayData.myName=this_enemy.data.myName;
                    this_enemy.sayData.enemy=this_enemy;
                    this_enemy.sayData.player=collision.gameObject.GetComponent<Player>();
                    this_enemy.sayData.playerHurtObj=collision.gameObject.GetComponent<PlayerHurtObj>();

                    PanelManager.Open<SayPanel>(this_enemy.sayData);
                    return;
                }
                //Debug.Log(collision.gameObject.GetComponent<PlayerHurtObj>()+" / "+
                //    collision.gameObject.GetComponent<Player>()+" / "+transform.parent.GetComponent<Enemy>());
                //开始攻击
                GameManager.Instance.StartBattle(collision.gameObject.GetComponent<PlayerHurtObj>(),
                    collision.gameObject.GetComponent<Player>(), transform.parent.GetComponent<Enemy>());
            }//父物体是门
            else if(transform.parent.GetComponent<Door>() != null)
            {
                transform.parent.GetComponent<Door>().OpenDoor();
            }//父物体是ShopMan
            else if(transform.parent.GetComponent<ShopMan>()!=null)
            {
                //打开UI
                transform.parent.GetComponent<ShopMan>().OpenShopUI();
            }
            else if (transform.parent.GetComponent<LoveMan>()!=null)
            {
                //打开UI
                transform.parent.GetComponent<LoveMan>().OpenLove();
            }
            else if (transform.parent.GetComponent<LightMan>()!=null)
            {
                //打开UI
                transform.parent.GetComponent<LightMan>().OpenLove();
            }
            else if (transform.parent.GetComponent<StatusOfWarrior>() != null)
            {
                //打开UI
                transform.parent.GetComponent<StatusOfWarrior>().OpenLove();
            }
            else if (transform.parent.GetComponent<MouseMan>() != null)
            {
                //打开UI
                transform.parent.GetComponent<MouseMan>().OpenLove();
            }
            else if (transform.parent.GetComponent<Book>() != null)
            {
                //打开UI
                transform.parent.GetComponent<Book>().OpenLove();
            }
            else if (transform.parent.GetComponent<TowerMan>() != null)
            {
                //打开UI
                transform.parent.GetComponent<TowerMan>().OpenLove();
            }
            else if (transform.parent.GetComponent<PoisonItem>() != null)
            {
                //打开UI
                transform.parent.GetComponent<PoisonItem>().OpenUI();
            }
            else if (transform.parent.GetComponent<BloodOfMoonItem>() != null)
            {
                //打开UI
                transform.parent.GetComponent<BloodOfMoonItem>().OpenUI();
            }
            else if (transform.parent.GetComponent<FinalSword>() != null)
            {
                //打开UI
                transform.parent.GetComponent<FinalSword>().OpenUI();
            }
            else if (transform.parent.GetComponent<Altar>() != null)
            {
                //打开UI
                transform.parent.GetComponent<Altar>().OpenLove();
            }
            else if (transform.parent.GetComponent<SkeletonFirstLayerDoor>() != null)
            {
                //打开UI
                transform.parent.GetComponent<SkeletonFirstLayerDoor>().OpenLove();
            }
            else if (transform.parent.GetComponent<SavePoint>() != null)
            {
                //打开UI
                transform.parent.GetComponent<SavePoint>().OpenLove();
            }
            else if (transform.parent.GetComponent<BloodFruit>() != null)
            {
                //打开UI
                transform.parent.GetComponent<BloodFruit>().OpenLove();
            }
            //关闭碰撞
            SceneItemManager.instance.ClearClickEnemy();
        }
    }
}